package com.atguigu.gmall.activity.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * @author: atguigu
 * @create: 2023-09-22 15:58
 */
@Configuration
public class CacheConfig {

    /**
     * 用于缓存商品状态缓存对象
     * Key：商品ID  Val：0（已售罄）1（秒杀中）
     *
     * @return
     */
    @Bean
    public Cache<String, String> seckillGoodsCache() {
        return Caffeine.newBuilder()
                .maximumSize(200)
                .expireAfterWrite(17, TimeUnit.HOURS)
                .build();
    }
}
